package tcpchat;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 创建客户端:发送数据+接收数据
 * 写出数据:输出流
 * 读取数据:输入流
 *
 * 输入流与输出流在同一个线程内 应该独立处理 彼此独立
 */
public class Client {
    public static void main(String[] args) {
        try {
            Socket client=new Socket("localhost",8888);
            //控制台输入流
            //Scanner sc=new Scanner(System.in);
            //String msg=sc.next();
            InputStreamReader isr=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(isr);
            String info=br.readLine();
            //输出流

            DataOutputStream dos=new DataOutputStream(client.getOutputStream());
            dos.writeUTF(info);
            dos.flush();
            //输入流
            DataInputStream dis=new DataInputStream(client.getInputStream());
            System.out.println(dis.readUTF());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
